package tung.niit.ict.adapter;

import java.util.ArrayList;

import tung.niit.ict.item.ItemLendedBook;
import tung.niit.ict.model.LendedBook;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class LendedBookAdapter extends ArrayAdapter<LendedBook>{

	private Context mContext;
	private ArrayList<LendedBook> arrayLendedBook;
	public LendedBookAdapter(Context context, int resource,
			ArrayList<LendedBook> objects) {
		super(context, resource, objects);
		
		mContext = context;
		arrayLendedBook = objects;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View itemLendedBook = convertView;
		if (itemLendedBook == null) {
			itemLendedBook = new ItemLendedBook(mContext);
		}
		LendedBook lendedBook = arrayLendedBook.get(position);
		if (lendedBook != null) {
			ImageView imgLendBookPic = ((ItemLendedBook)itemLendedBook).imgBook;
			TextView  tvNameBook = ((ItemLendedBook)itemLendedBook).tvNameBook;
			TextView tvAuthorBook = ((ItemLendedBook)itemLendedBook).tvAuthorBook;
			TextView tvIdBook = ((ItemLendedBook)itemLendedBook).tvIdBook;
			TextView tvYearBook = ((ItemLendedBook)itemLendedBook).tvYearBook;
			TextView tvSoTienCuocBook = ((ItemLendedBook)itemLendedBook).tvSotiencuocBook;
			
			imgLendBookPic.setImageBitmap(lendedBook.getBookPic());
			tvNameBook.setText(lendedBook.getNameBook());
			tvAuthorBook.setText(lendedBook.getAuthorBook());
			tvIdBook.setText(lendedBook.getIdBook());
			tvYearBook.setText(lendedBook.getYearBook());
			tvSoTienCuocBook.setText(lendedBook.getTiencuocBook());
		}
		return itemLendedBook;
	}
	
}
